class Solution(object):
    def groupAnagrams(self, strs):
        """
        :type strs: List[str]
        :rtype: List[List[str]]
        """

        from collections import defaultdict
        # 利用字典的特性,key有的话就添加值,没有的话就创建key并添加值
        dic = defaultdict(list)

        for i in strs:
            res = ''.join(sorted(i))
            dic[res].append(i)
        return dic
   
            

print(Solution().groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))